
export function test1() {
  /**
   * 程序创建了一个promise,这个timeout也会继续执行,完成后才会退出执行线程.
   */
  let taskA = new Promise<void>((resolve) => {
    console.log("start");
    setTimeout(() => {
      console.log("end");
      resolve();
    }, 300);
  });
}

//promise创建后,executor就自动派发到队列中去了,不能自定义什么时候开始执行.
function getCost2PromiseTask(): Promise<void> {
  //同步执行2秒的函数.
  let task = new Promise((resolve: (value: void) => void) => {
    let d1 = new Date();
    let t1 = d1.getTime();
    console.log(`[${d1.toISOString()}][task start] [${name}]`)
    while (true) {
      let d2 = new Date();
      let t2 = d2.getTime();
      let dif = t2 - t1;
      if (dif >= 2000) {
        console.log(`[${d2.toISOString()}][task end] [${name}]`)
        break;
      }
    }
    resolve();
  });
  return task;
}
